/**
 * @file xcd_log.c
 * @brief Logging functions
 * @author Guo-Rong Koh
 * @date 6 April 2008
 *
 * @par Copyright Notice
 * Copyright Guo-Rong Koh 2008.
 */

/*
 * This file is part of xceed.
 *
 * xceed is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License Version 2 as published by the Free
 * Software Foundation.
 *
 * xceed is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * xceed.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdarg.h>
#include <stdio.h>

#include "config.h"
#include "xcd_log.h"

/** Maximum log length in bytes. */
#define XCD_LOG_MAX 1024

void xcd_logf(xcd_log_level_t log_level,
              const char     *format,
              ...)
{
    char   *log_prefix = NULL;
    char    log_message[XCD_LOG_MAX];
    va_list ap;

    va_start(ap, format);
    vsnprintf(log_message, XCD_LOG_MAX, format, ap);
    va_end(ap);

    switch (log_level)
    {
        case XCD_LOG_DEBUG:
            log_prefix = "DEBUG";
            break;
        case XCD_LOG_ERROR:
            log_prefix = "ERROR";
            break;
        default:
            log_prefix = "";
    }

    fprintf(stderr, "%s: %s: %s", XCD_NAME, log_prefix, log_message);
}
